package com.xrh.core.generater.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

//正则工具类
public class RegexUtils {

	//下划线表名匹配
	public final static Pattern UNDERLINE_TABLENAME_PATTERN = Pattern.compile("_\\w{1}");

	//生成类名
	public static String generateClassName(String tableName){
		
		String className = tableName.toLowerCase();
		
		if(className.indexOf("_") != -1){
			Matcher m = UNDERLINE_TABLENAME_PATTERN.matcher(className);
			while(m.find()){
				className = className.replaceAll(m.group(), m.group().toUpperCase().replace("_", ""));
			}
		} 
		
		return MyStringUtils.uppercaseIndexLetter(className);
		
	}
	
	//生成属性名
	public static String generatePropertyName(String columnName){
		
		String propertyName = columnName;
		
		if(propertyName.indexOf("_") != -1){
			propertyName = propertyName.toLowerCase();
			Matcher m = UNDERLINE_TABLENAME_PATTERN.matcher(propertyName);
			while(m.find()){
				propertyName = propertyName.replaceAll(m.group(), m.group().toUpperCase().replace("_", ""));
			}
			return propertyName;
		} 
		
		return MyStringUtils.lowercaseIndexLetter(propertyName);
	}
	
}
